<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/js/jquery-2.2.3.min.js}" charset="utf-8"></script>
    <link rel="shortcut icon" href="../resources/favicon.ico" th:href="@{/static/favicon.ico}"/>

</head>
<body>



<form class="layui-form" id="adminproject" style="display:none">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" required  autocomplete="on"
                   class="layui-input" id="title">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">详细内容</label>
        <div class="layui-input-block">
            <!--            <input type="text" name="content" required  autocomplete="on"-->
            <!--                   class="layui-input" id="content" size="100">-->
            <textarea    required name="content" id="content" style="width: 800px;height: 100px"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">希望完成时间</label>
        <div class="layui-input-block">
            <input type="date" name="hopetime" lay-verify="required" autocomplete="on"
                   class="layui-input" id="hopetime">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" name="author" required  autocomplete="on"
                   class="layui-input" id="author">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">分类标签</label>
        <div class="layui-input-block">
            <select id="kind" name="kind" lay-verify="required" lay-filter="business" class="select">
                <option value=""></option>
                <option value="软件系统故障">软件系统故障</option>
                <option value="硬件系统故障">硬件系统故障</option>
                <option value="网络安全">网络安全</option>
                <option value="其他">其他</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">紧急程度</label>
        <div class="layui-input-block">
            <select id="urgent" name="urgent" lay-verify="required" lay-filter="business" class="select">
                <option value=""></option>
                <option value="高">高</option>
                <option value="中">中</option>
                <option value="低">低</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>

        </div>
    </div>
    <div style="display: none">
        <input type="number" name="id" id="id">
    </div>
</form>
<form class="layui-form" id="adminproject2" style="display:none">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" required  autocomplete="on"
                   class="layui-input" id="title2" disabled="true">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">详细内容</label>
        <div class="layui-input-block">
            <!--            <input type="text" name="content" required  autocomplete="on"-->
            <!--                   class="layui-input" id="content" size="100">-->
            <textarea    required name="content" id="content2" style="width: 800px;height: 100px" disabled="true"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">希望完成时间</label>
        <div class="layui-input-block">
            <input type="date" name="hopetime" lay-verify="required" autocomplete="on"
                   class="layui-input" id="hopetime2" disabled="true">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" name="author" required  autocomplete="on"
                   class="layui-input" id="author2"  disabled="true">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">分类标签</label>
        <div class="layui-input-block">
            <select id="kind2" name="kind" lay-verify="required" lay-filter="business" class="select" disabled="true">
                <option value=""></option>
                <option value="软件系统故障">软件系统故障</option>
                <option value="硬件系统故障">硬件系统故障</option>
                <option value="网络安全">网络安全</option>
                <option value="其他">其他</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">紧急程度</label>
        <div class="layui-input-block">
            <select id="urgent2" name="urgent" lay-verify="required" lay-filter="business" class="select" disabled="true">
                <option value=""></option>
                <option value="高">高</option>
                <option value="中">中</option>
                <option value="低">低</option>
            </select>
        </div>
    </div>
</form>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<table class="layui-hide" id="test" lay-filter="test"></table>

<script>
    //表单
    layui.use(["table", "form"], function () {
        var table = layui.table;
        var form = layui.form;
        ptable= function () {
            table.render({
                elem: '#test'
                , url: '/support/chartlistdata'
                , toolbar: '#toolbarDemo'
                , title: '用户数据表'
                , limit: 10
                , page: true
                , cols: [
                    [
                        {type: 'checkbox', fixed: 'left'}
                        , {
                        field: 'id',
                        title: 'ID',
                        width: 80,
                        fixed: 'left',
                        unresize: true,
                        sort: true,
                        totalRowText: '合计'
                    }

                        , {field: 'title', title: '标题', width: 200}
                        , {field: 'publishtime', title: '提交时间', width: 200}
                        , {field: 'author', title: '提交者', width: 100}
                        , {field: 'urgent', title: '紧急程度', width: 100}
                        , {field: 'status', title: '工单状态', width: 150}
                        , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
                    ]
                ]

            });
        }
        ptable();



        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                if(data.status=="退回")
                {
                    layer.confirm('真的删除行么', function (index) {
                        var id = data.id;
                        $.ajax({
                            url: '/support/chartlistdelete',
                            type: "POST",
                            data: {"id": id},
                            success: function () {
                                ptable();

                            }
                        });
                        layer.close(index);
                    });
                }
                else {
                    layer.msg("无权限")
                }



            }
            if (obj.event === 'look') {



                layer.open({
                    type: 1,
                    area: ['1000px', '500px'],
                    title: '项目名'
                    , content: $("#adminproject2"),
                    shade: 0

                    , success: function (layero, index) {
                        var div = layero.contents().find('#adminproject2');

                        div.find("#title2").val(data.title);
                        div.find("#author2").val(data.author);
                        div.find("#kind2").val(data.kind);
                        div.find("#urgent2").val(data.urgent);
                        div.find("#hopetime2").val(data.hopetime);
                        div.find("#content2").val(data.content);
                        form.render();

                    }


                });
















            }
            else if (obj.event === 'edit') {


                if(data.status=="退回")
                {
                    layer.open({
                        type: 1,
                        area: ['1000px', '500px'],
                        title: '项目名'
                        , content: $("#adminproject"),
                        shade: 0

                        , success: function (layero, index) {
                            var div = layero.contents().find('#adminproject');
                            div.find("#id").val(data.id);
                            div.find("#title").val(data.title);
                            div.find("#author").val(data.author);
                            div.find("#kind").val(data.kind);
                            div.find("#urgent").val(data.urgent);
                            div.find("#hopetime").val(data.hopetime);
                            div.find("#content").val(data.content);


                            form.render();

                        }
                    });
                }
                else {
                    layer.msg("无权限")
                }







            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var title = $("#title").val();

            var author = $("#author").val();
            var kind = $("#kind").val();
            var hopetime = $("#hopetime").val();

            var urgent = $("#urgent").val();
            var content = $("#content").val();
            var id = $("#id").val();
            var id2 =  parseInt(id)
            $.ajax({
                url: '/support/chartlistupdate',
                type: "POST",
                traditional: true,
                data: {
                    "title": title,
                    "author": author,
                    "kind": kind,
                    "hopetime":hopetime,
                    "id":id2,

                    "urgent": urgent,

                },
                success: function () {

                    ptable();
                    layer.closeAll();
                    layer.msg('修改成功');



                }
            });

            return false;
        });







    });


</script>
</body>
</html>